package net.melon.product.inst.struts2;

import javax.annotation.Resource;

import net.esj.basic.view.AbstractPluginPageAction;
import net.melon.product.inst.service.impl.SpecificationsValueCacheProxy;
import net.melon.product.pojo.ProductSpecificationsValue;
import net.melon.uploader.Uploader;

public class SpecificationsValueAction extends AbstractPluginPageAction<ProductSpecificationsValue, ProductSpecificationsValue>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 9062775915603177206L;

	private long type;
	private boolean add;
	private boolean delete;
	private boolean edit;
	private boolean image;
	
	@Resource
	private SpecificationsValueCacheProxy specificationsValueCacheProxy;
	
	@Override
	protected void doQueryPage() {
		pagination.getQueryBuilder().fetch("specifications").eq("specifications.id", type);
		super.doQueryPage();
	}
	
	@Override
	protected void doGetEntity() {
		entity = defaultService.get(Long.valueOf(id), ProductSpecificationsValue.class);
	}
	
	@Override
	protected void doAdd() throws Exception {
		entity.setState(1);
		specificationsValueCacheProxy.saveProductSpecificationsValue(entity);
	}
	
	@Override
	protected void doUpdate() throws Exception {
		specificationsValueCacheProxy.updateProductSpecificationsValue(entity);
	}
	
	@Override
	protected void doDelete() throws Exception {
		specificationsValueCacheProxy.deleteProductSpecificationsValue(Long.valueOf(id),true);
	}
	
	public String getDownloadUrl(){
		return Uploader.getDownUrl(ProductSpecificationsValue.ICON_DIR);
	}
	
	public long getType() {
		return type;
	}
	public void setType(long type) {
		this.type = type;
	}
	public boolean isAdd() {
		return add;
	}
	public void setAdd(boolean add) {
		this.add = add;
	}
	public boolean isDelete() {
		return delete;
	}
	public void setDelete(boolean delete) {
		this.delete = delete;
	}
	public boolean isEdit() {
		return edit;
	}
	public void setEdit(boolean edit) {
		this.edit = edit;
	}
	public boolean isImage() {
		return image;
	}
	public void setImage(boolean image) {
		this.image = image;
	}
	
	public ProductSpecificationsValue getEntity(){
		return entity;
	}
	
	public void setEntity(ProductSpecificationsValue entity){
		this.entity = entity;
	}
}
